# -*- coding: utf-8 -*-
# @Time : 2021/4/28 15:22
# @Author : 张宇鹏
# @FileName: a1.py
import csv
dic1 = {}
dic2 = {}
dic3 = {}
dic4 = {}
set1 = set()
with open("peptide_A.csv") as f1:
    reader1 = csv.DictReader(f1)
    for row in reader1:
        dic1[row["Peptide"]] = row["Area Sample 1"]
        dic3[row["Peptide"]] = row["PTM"]
        dic4[row["Peptide"]] = row["Accession"]
        set1.add(row["Peptide"])

with open("peptide_J.csv") as f2:
    reader2 = csv.DictReader(f2)
    for row in reader2:
        dic2[row["Peptide"]] = row["Area Sample 2"]
        dic3[row["Peptide"]] = row["PTM"]
        dic4[row["Peptide"]] = row["Accession"]
        set1.add(row["Peptide"])

print(len(set1))

with open("aj.csv", mode='w', newline="", encoding='utf-8') as f3:
    writer = csv.writer(f3)
    head = ["Peptide","A","J","PTM","Accession"]
    writer.writerow(head)
    save = []
    for x in set1:
        save.append(x)
        if dic1.__contains__(x):
            save.append(dic1[x])
        else:
            save.append("")

        if dic2.__contains__(x):
            save.append(dic2[x])
        else:
            save.append("")
        save.append(dic3[x])
        save.append(dic4[x])
        writer.writerow(save)
        save = []


